<?php

namespace XWAM\Addon\POrgUser\Controller;

/**
 * Description of LoginController
 *
 * @since 1.0 <2015-10-20> SoChishun <14507247@qq.com> Added.
 */
class LoginController extends \Think\Controller {

    public function index() {
        $this->display();
    }

    public function login() {
        $user_name = I('login_name');
        $captcha = I('captcha');
        if (!isset($_POST['captcha'])) {
            $captcha = null;
        }
        $pwd = I('password');
        if (!$user_name || !$pwd || (!is_null($captcha) && !$captcha)) {
            $this->error('表单填写不完整!');
        }
        $result = AddonD('Login')->login($user_name, $pwd, $captcha, $msg);
        if ($result) {
            session(C('USER.SESSION_ID'), $msg);
            redirect(U('Index/index'));
        } else {
            $this->error($msg);
        }
    }

    public function logout() {
        AddonD('Login')->logout();
        header('location:' . AddonU('Login/index'));
    }

}
